/**
 * @param {number} n
 * @return {number}
 * @description 二分法
 */

var arrangeCoins = function (n) {
    let left = 1
    let right = n
    let mid = right - Math.floor((right - left) / 2)
    while (left <= right) {
        if (mid * (mid + 1) / 2 > n) {
            right = mid - 1
        } else if (mid * (mid + 1) / 2 < n) {
            left = mid + 1
        } else {
            return mid
        }
        mid = right - Math.floor((right - left) / 2)
    }
    return right
};
